/**************************************************************************
 * @doc SCAPI
 * @module SCDEFINE.H - Common Header code for SCAPI functions.|  
 * Common Header code for SCAPI functions.
 *
 * Product     :   SoftPay 2000 (Global Payment Methodology).
 * <nl>Developer   :   SoftPay Development Team (I_SP2000).
 * <nl>Notes       :
 *
 * @head3 SCAPI Functions |
 * @index | GPM
 * @end
 *
 * Copyright (c) 1996-2000 by VeriFone Inc. All rights reserved.
 * 
 * No part of this software may be used, stored, compiled, reproduced,
 * modified, transcribed, translated, transmitted, or transferred, in any form 
 * or by any means whether electronic, mechanical, magnetic, optical, 
 * or otherwise, without the express prior written permission of VeriFone, Inc.
 *
 * Revision History
 * ------------------------------------------------------------------------
 $Log: /SoftPay/SPK2SIM/Source/Scapi/scdefine.h $
 * 
 * 2     12/30/99 5:13p Sadiq_m1
 * Re-organized functions
 * 
 * 3     11/09/99 10:07p Sadiq_m1
 * 
 * 2     11/04/99 10:11p Sadiq_m1
 *
 * 1	 10/31/99  8:45p Sadiq_m1    Initial version  
 * ------------------------------------------------------------------------
 ********************************************************************************/

#ifndef SCDEF_H
#define SCDEF_H

#define SC_DEBUG     0    

/**************** Some useful type definitions used throughout *************/

#ifndef __ARM
#ifndef __WORD__
#define __WORD__
typedef unsigned int  WORD;
#endif
#endif

#ifdef __ARM
#ifndef __WORD__
#define __WORD__
typedef unsigned short WORD;
#endif

#endif

typedef char SC_BOOL;

typedef enum { PRIMARY_SCR, SECONDARY_SCR } CARD_SLOT;

#define SC_FALSE           ((SC_BOOL) 0)
#define SC_TRUE            ((SC_BOOL) 1)

/************** Some useful constant definitions used throughout ***********/

#define SC_SUCCESS               ((int)   0)   /* General purpose err code  */
#define SC_ERR                   ((int)(-1))                               


/***************** Other constant definitions used throughout ***************/

//#define SC_CMD_FNAME                       "SCCMDMSG.DAT"

#define SC_CMD_LEN                         4   /* Req - Sxxx, Resp - Rxxx   */

#define SC_COMM_MAX_RETRY                  3   /* Maximum of three retries  */
#define SC_MAX_BUF_SIZE                  259   /* 100 *//* 128 *//* maximum */
                                               /* pkt size at LLP           */
#define SC_ACK_TIMEOUT                     3   /* 2000 ms = 200 * 10 ms     */
#define SC_TIMEOUT						  40   /* 6 secs delay				*/

#define MIN_SC_RESPONSE_SIZE               4   /* Minimum size is 4 bytes   */
#define DEF_RETRY_COUNT                    3   /* Maximum num of retries    */
#define DEF_ACK_TIME_OUT                  45   /* Max wait time for an ack  */
#define DEF_TIME_OUT                      40   /* Timeout for reply         */
#define MAX_PACKET_SIZE                  200   /* Maximum packet size       */


                                    /* Definitions for SCR setup and others */
#define SC_COMM_DB_7                       0
#define SC_COMM_DB_8                       1
#define SC_COMM_PARITY_EVEN                2
#define SC_COMM_PARITY_ODD                 3
#define SC_COMM_PARITY_NONE                4
#define SC_COMM_SB_1                       5
#define SC_COMM_SB_2                       6
#define SC_COMM_CIPHERED                   7
#define SC_COMM_NORMAL                     8
#define SC_COMM_BAUD_1200                  9
#define SC_COMM_BAUD_2400                 10
#define SC_COMM_BAUD_4800                 11
#define SC_COMM_BAUD_9600                 12
#define SC_COMM_BAUD_19200                13

/* GPM Cards related */

#define SC_GPM896_MANUFACTURER_AREA        0
#define SC_GPM896_ISSUER_AREA              1
#define SC_GPM896_CSC_AREA                 2
#define SC_GPM896_ERROR_COUNTER            3
#define SC_GPM896_PROTECTED_AREA           4
#define SC_GPM896_GENERAL_AREA             4
#define SC_GPM896_APPLICATION_AREA1        5
#define SC_GPM896_ERASE_CODE1              6
#define SC_GPM896_APPLICATION_AREA2        7
#define SC_GPM896_ERASE_CODE2              8
#define SC_GPM896_ERASE_COUNTER            9
                                           
#define SC_GPM896                          0
#define SC_NO_ENCRYPTION                   0
#define SC_DES_ENCRYPTION                  1
#define SC_ALGO1_ENCRYPTION                2
#define SC_ALGO2_ENCRYPTION                3

                                         
                                                 /* Console related defines */
#define SC_BEEP_NONE                      00
#define SC_BEEP_NORMAL_SINGLE             01
#define SC_BEEP_ERROR_SINGLE              03
#define SC_BEEP_NORMAL_FOREVER            05
#define SC_BEEP_ERROR_FOREVER             07

#define SC_PROMPT_DEFAULT                 00
#define SC_PROMPT_IN_LINE                 01
#define SC_PROMPT_MSG_SLOT                02
                                         
#define SC_RD_BIN_MAX                     32       /* Max read is 32 bytes  */ 
#define SC_WR_BIN_MAX                     32       /* Max write is 32 bytes */ 

#define SC_CHILD_DF_TYPE       1          /* Sel DF when MF is selected     */
#define SC_CHILD_EF_TYPE       2          /* Sel EF under current DF        */
#define SC_PARENT_DF_TYPE      3          /* Sel Parent DF above current DF */
#define SC_NAMED_DF_TYPE       4          /* Sel DF by its name             */

#define SC_MAX_SHORT_ID_SIZE   2          /* Bytes to hole the SID of file  */
#define SC_ACT_REC_LEN_BUF     2          /* Bytes to hold new len of rec.  */

#define SC_MAX_READ_REC_LENGTH 128        /* Max Resp Buf size for ReadRec()*/
#define SC_MAX_VEE_FILE_NAME_SZ     16    /* Max VEE File Name Size         */
#define SC_MAX_MC_VEE_FILE_NAME_SZ  22    /* Max M/C VEE File Name Size     */


                   /* Various Smart card operations. These values should be */
                   /* one to one corresponding to entries in SCCMDMSG.DAT   */
                   /* Each line in the file SCCMDMSG.DAT SHOULD BE 6 char   */
                   /* long 4 char message (Eg. "S001") + CR + LF            */

#define SC_CMD_RESET                       0                        /* S001 */
#define SC_RSP_RESET                       1                        /* R001 */
#define SC_CMD_SW_OFF                      2                        /* S002 */
#define SC_RSP_SW_OFF                      3                        /* R002 */
#define SC_CMD_TST_CRD_PRES                4                        /* S003 */
#define SC_RSP_TST_CRD_PRES                5                        /* R003 */
#define SC_CMD_RESET_SSCR                  6                        /* S501 */
#define SC_RSP_RESET_SSCR                  7                        /* R501 */
#define SC_CMD_SW_OFF_SSCR                 8                        /* S502 */
#define SC_RSP_SW_OFF_SSCR                 9                        /* R502 */
#define SC_CMD_TST_CRD_PRES_SSCR          10                        /* S503 */
#define SC_RSP_TST_CRD_PRES_SSCR          11                        /* R503 */
#define SC_CMD_ISO_IN                     12                        /* S201 */
#define SC_RSP_ISO_IN                     13                        /* R201 */
#define SC_CMD_ISO_OUT                    14                        /* S202 */
#define SC_RSP_ISO_OUT                    15                        /* R202 */
#define SC_CMD_ISO_IN_SSCR                16                        /* S701 */
#define SC_RSP_ISO_IN_SSCR                17                        /* R701 */
#define SC_CMD_ISO_OUT_SSCR               18                        /* S702 */
#define SC_RSP_ISO_OUT_SSCR               19                        /* R702 */
#define SC_CMD_DISP_PROMPT                20                        /* P001 */
#define SC_RSP_DISP_PROMPT                21                        /* Q001 */
#define SC_CMD_GET_SER_NO                 22                        /* P002 */
#define SC_RSP_GET_SER_NO                 23                        /* Q002 */
#define SC_CMD_GET_RAND_NO                24                        /* P003 */
#define SC_RSP_GET_RAND_NO                25                        /* Q003 */
#define SC_CMD_SET_BEEPER                 26                        /* P004 */
#define SC_RSP_SET_BEEPER                 27                        /* Q004 */
#define SC_CMD_LOAD_MSG                   28                        /* P005 */
#define SC_RSP_LOAD_MSG                   29                        /* Q005 */
#define SC_CMD_TEST                       30                        /* P006 */
#define SC_RSP_TEST                       31                        /* Q006 */

/* Custom Commands */                                          

#define SC_CMD_CROSS_AUTH                 32                        /* C001 */
#define SC_RSP_CROSS_AUTH                 33                        /* D001 */
#define SC_CMD_READ_BIN                   34                        /* C002 */
#define SC_RSP_READ_BIN                   35                        /* D002 */
#define SC_CMD_READ_BIN_SSCR              36                        /* C502 */
#define SC_RSP_READ_BIN_SSCR              37                        /* D502 */
#define SC_CMD_UPDATE_BIN                 38                        /* C003 */
#define SC_RSP_UPDATE_BIN                 39                        /* D003 */
#define SC_CMD_UPDATE_BIN_SSCR            40                        /* C503 */
#define SC_RSP_UPDATE_BIN_SSCR            41                        /* D503 */
#define SC_CMD_READ_BAL                   42                        /* C004 */
#define SC_RSP_READ_BAL                   43                        /* D004 */
#define SC_CMD_CREDIT                     44                        /* C005 */
#define SC_RSP_CREDIT                     45                        /* D005 */
#define SC_CMD_DEBIT                      46                        /* C006 */
#define SC_RSP_DEBIT                      47                        /* D006 */
#define SC_CMD_VERIFY                     48                        /* C007 */
#define SC_RSP_VERIFY                     49                        /* D007 */
#define SC_CMD_VERIFY_SSCR                50                        /* C507 */
#define SC_RSP_VERIFY_SSCR                51                        /* D507 */
#define SC_CMD_WRITE_BIN                  52                        /* C008 */
#define SC_RSP_WRITE_BIN                  53                        /* D008 */
#define SC_CMD_WRITE_BIN_SSCR             54                        /* C508 */
#define SC_RSP_WRITE_BIN_SSCR             55                        /* D508 */

#define SC_CMD_GET_PIN                    56                        /* P102 */
#define SC_RSP_GET_PIN                    57                        /* Q102 */
#define SC_CMD_CANCEL_PIN                 58                        /* P103 */
#define SC_RSP_CANCEL_PIN                 59                        /* Q103 */
                                        
/* GPM Commands */

#define SC_CMD_RD_MEM                     60                        /* S101 */
#define SC_RSP_RD_MEM                     61                        /* R101 */
#define SC_CMD_WR_MEM                     62                        /* S102 */
#define SC_RSP_WR_MEM                     63                        /* R102 */
#define SC_CMD_ERASE_MEM                  64                        /* S103 */
#define SC_RSP_ERASE_MEM                  65                        /* R103 */
#define SC_CMD_RD_AREA                    66                        /* S104 */
#define SC_RSP_RD_AREA                    67                        /* R104 */
#define SC_CMD_WR_AREA                    68                        /* S105 */
#define SC_RSP_WR_AREA                    69                        /* R105 */
#define SC_CMD_ERASE_AREA                 70                        /* S106 */
#define SC_RSP_ERASE_AREA                 71                        /* R106 */
#define SC_CMD_PRES_CSC                   72                        /* S107 */
#define SC_RSP_PRES_CSC                   73                        /* R107 */
#define SC_CMD_WR_CSC                     74                        /* S108 */
#define SC_RSP_WR_CSC                     75                        /* R108 */
#define SC_CMD_ENABLE_PER                 76                        /* S109 */
#define SC_RSP_ENABLE_PER                 77                        /* R109 */

                                     /* Definitions for various error types */

#define ERR_SC_ALREADY_OPEN              (-3) /* port is already open       */
#define ERR_SC_MODE_ERR                  (-4) /* iCommMode is invalid       */
#define ERR_SC_CLOSE_FAIL                (-5) /* port close failed          */
#define ERR_SC_INVALID_COMMAND           (-6) /* SCR response = R000        */
#define ERR_SC_CARD_REMOVED              (-7) /* if SC reader resp = 000D   */
#define ERR_SC_SEC_CODE_FAIL             (-8) /* if SC response = 63Cn      */
#define ERR_SC_COMM_BUF_FAIL             (-9) /* if SC response = 6Cnn      */

#define ERR_SC_INVALID_RESPONSE         (-11) /* resp from SCR is invalid   */
#define ERR_SC_COMMAND_FAIL             (-12) /* SCR response code = 900x   */
#define ERR_SC_INVALID_PARAM            (-14) /* invalid param was passed   */
#define ERR_SC_CARD_NOT_PRESENT         (-15) /* SCR response = 0000        */
#define ERR_SC_HW_ERRORS                (-16) /* SCR response = 000X        */
#define ERR_SC_MPCOS_INV_RESPONSE       (-17) /* status of SCR resp invalid */
#define ERR_SC_MPCOS_6103               (-18) /* if SC reader resp = 6103   */
#define ERR_SC_MPCOS_6284               (-19) /* if SC reader resp = 6284   */
#define ERR_SC_MPCOS_6700               (-20) /* if SC reader resp = 6700   */
#define ERR_SC_MPCOS_6900               (-21) /* if SC reader resp = 6900   */
#define ERR_SC_MPCOS_6981               (-22) /* if SC reader resp = 6981   */
#define ERR_SC_MPCOS_6982               (-23) /* if SC reader resp = 6982   */
#define ERR_SC_MPCOS_6983               (-24) /* if SC reader resp = 6983   */
#define ERR_SC_MPCOS_6985               (-25) /* if SC reader resp = 6985   */
#define ERR_SC_MPCOS_6A80               (-26) /* if SC reader resp = 6A80   */
#define ERR_SC_MPCOS_6A82               (-27) /* if SC reader resp = 6A82   */
#define ERR_SC_MPCOS_6A84               (-28) /* if SC reader resp = 6A84   */
#define ERR_SC_MPCOS_6B00               (-29) /* if SC reader resp = 6B00   */
#define ERR_SC_MPCOS_6C10               (-30) /* if SC reader resp = 6C10   */
#define ERR_SC_MPCOS_6C13               (-31) /* if SC reader resp = 6C13   */
#define ERR_SC_MPCOS_6C60               (-32) /* if SC reader resp = 6C60   */
#define ERR_SC_MPCOS_6C63               (-33) /* if SC reader resp = 6C63   */
#define ERR_SC_MPCOS_6D00               (-34) /* if SC reader resp = 6D00   */
#define ERR_SC_MPCOS_6E00               (-35) /* if SC reader resp = 6E00   */
                                         
                                         
#define ERR_SC_MPCOS_9100               (-36) /* if SC reader resp = 9100   */
#define ERR_SC_MPCOS_9102               (-37) /* if SC reader resp = 9102   */
#define ERR_SC_MPCOS_9202               (-38) /* if SC reader resp = 9202   */
#define ERR_SC_MPCOS_9400               (-39) /* if SC reader resp = 9400   */
#define ERR_SC_MPCOS_9404               (-40) /* if SC reader resp = 9404   */
#define ERR_SC_MPCOS_9406               (-41) /* if SC reader resp = 9406   */
#define ERR_SC_MPCOS_9408               (-42) /* if SC reader resp = 9408   */
#define ERR_SC_MPCOS_9800               (-43) /* if SC reader resp = 9800   */
#define ERR_SC_MPCOS_9802               (-44) /* if SC reader resp = 9802   */
#define ERR_SC_MPCOS_9804               (-45) /* if SC reader resp = 9804   */
#define ERR_SC_MPCOS_9806               (-46) /* if SC reader resp = 9806   */
#define ERR_SC_MPCOS_9810               (-47) /* if SC reader resp = 9810   */
#define ERR_SC_MPCOS_9820               (-48) /* if SC reader resp = 9820   */
#define ERR_SC_MPCOS_9840               (-49) /* if SC reader resp = 9840   */

                                         /* Link level protocol error codes */
#define ERR_SC_USER_ABORT               (-100)
#define ERR_SC_WRITE_FAIL               (-101)
#define ERR_SC_READ_FAIL                (-102)
#define ERR_SC_OPEN_FAIL                (-103)
#define ERR_SC_INIT_FAIL                (-104)
#define ERR_SC_COMMS_NO_ACK             (-105)
#define ERR_SC_COMMS_SEND_FAIL          (-106)
#define ERR_SC_COMMS_TIMOUT             (-107)
#define ERR_SC_RECV_FAIL                (-108)
#define ERR_SC_NO_BUFFER                (-109)
#define ERR_SC_REC_LEN_TOO_LARGE        (-110)
#define ERR_SC_INV_RDREC_RESP           (-111)

#define ERR_FILE_INTERGRITY             (-201)
#define ERR_INV_LEN_OR_ADD              (-202)
#define ERR_FILE_NOT_FOUND              (-203)
#define ERR_INV_PARAM_PASSED            (-204)
#define ERR_CANNOT_SEL_FILE             (-205)
#define ERR_INV_LENGTH                  (-206)
#define ERR_CMD_OPTION_NOT_SELECT       (-207)
#define ERR_INCORRECT_APPLN             (-208)
#define ERR_EMV_WARNING_ERROR           (-209)
#define ERR_SC_INCONSISTENT_PIN         (-210)
#define ERR_SC_CMD_EXEC_FAIL            (-211)
#define ERR_SECRET_CODE_LOCKED          (-212)

extern int hSCR;

extern const char *pszFmt;                                           /* = "%02X"  */
extern const char *pszFmt1;                                          /* = "%04X"  */
extern const char *pszFmt2;                                          /* = "%06lX" */


extern const char *pszMaxRead;                                       /* = "74"    */
extern const char *pszNewLenSW;                                      /* = "6C"    */
extern const char *pszGetRespSW;                                     /* = "61"    */

extern char *TblMsgIDs[];

#endif /* SCDEF_H */
